package com.excel.analysis;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.google.gson.JsonArray;
import com.google.gson.JsonObject;

public class ExcelBean {

	private int startRow;
	private int endRow;
	private int startColumn;
	private int endColumn;
	private int merge; // 0不是合并单元格，1行合并，2列合并
	private String value;
	private String code;
	private Map<String, String> params = new HashMap<String, String>();

	private List<ExcelBean> beans = new ArrayList<ExcelBean>();

	public String rowspan() {
		if (endRow != startRow) {
			return String.valueOf(endRow - startRow + 1);
		} else {
			return "0";
		}
	}

	public String colspan() {
		if (endColumn != startColumn) {
			return String.valueOf(endColumn - startColumn + 1);
		} else {
			return "0";
		}
	}

	/**
	 * 加入行
	 * 
	 * @param row
	 */
	public void addBean(ExcelBean excelBean) {
		beans.add(excelBean);
	}

	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}

	public int getStartRow() {
		return startRow;
	}

	public void setStartRow(int startRow) {
		this.startRow = startRow;
	}

	public int getEndRow() {
		return endRow;
	}

	public void setEndRow(int endRow) {
		this.endRow = endRow;
	}

	public int getStartColumn() {
		return startColumn;
	}

	public void setStartColumn(int startColumn) {
		this.startColumn = startColumn;
	}

	public int getEndColumn() {
		return endColumn;
	}

	public void setEndColumn(int endColumn) {
		this.endColumn = endColumn;
	}

	public int getMerge() {
		return merge;
	}

	public void setMerge(int merge) {
		this.merge = merge;
	}

	public List<ExcelBean> getBeans() {
		return beans;
	}

	public void setBeans(List<ExcelBean> beans) {
		this.beans = beans;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getJsonValue(String key) {
		JsonObject jsonObject = GsonUtils.getValues(value);
		Object o = jsonObject.get(key);
		if (o != null) {
			return jsonObject.get(key).getAsString();
		} else {
			return null;
		}
	}

	public List<String> getJsonValues(String key) {
		List<String> dataList = new ArrayList<String>();
		JsonObject jsonObject = GsonUtils.getValues(value);
		JsonArray o = jsonObject.getAsJsonArray(key);
		if(o != null) {			
			for (int i = 0; i < o.size(); i++) {
				dataList.add(o.get(i).getAsString());
			}
		}
		return dataList;
	}
	
	public JsonArray getJson(String key) {
		JsonObject jsonObject = GsonUtils.getValues(value);
		JsonArray o = jsonObject.getAsJsonArray(key);
		return o;
	}

	public Map<String, String> getParams() {
		return params;
	}
	
	public String getValueByKey(String key) {
		return params.get(key);
	}

	public void setParams(Map<String, String> params) {
		this.params = params;
	}
	
	public void addValue(String key, String value) {
		params.put(key, value);
	}

	public static void main(String[] args) {
		JsonObject jsonObject = GsonUtils
				.getValues("{field:busiType,type:plainList,dataArray:[开户,存款,取款,咨询,换钞]}");
		JsonArray o = jsonObject.getAsJsonArray("dataArray");
		for (int i = 0; i < o.size(); i++) {
			System.out.println(o.get(i));
		}
	}
}
